//
//  ST_TIANLightNavigationBar.swift
//  btvideo
//
//  Created by Jason on 2021/10/27.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift
import NSObject_Rx




class ST_TIANLightNavigationBar: UIView {
    
    override init(frame: CGRect){
        super.init(frame: frame)
        
        backgroundColor = .white
        addSubview(left_nav_btn)
        addSubview(title_nav_btn)
        addSubview(right_nav_btn)
        
        left_nav_btn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(8)
            make.bottom.equalToSuperview()
            make.width.height.equalTo(44)
        }
        
        right_nav_btn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-14)
            make.bottom.equalToSuperview()
            make.width.height.equalTo(44)
        }
        
        title_nav_btn.snp.makeConstraints { (make) in
            make.height.equalTo(44)
            make.top.equalToSuperview().offset(statusBarHeight)
            make.centerX.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    lazy var left_nav_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.setImage(ST_ImageUtils.imageName("返回_gray"), for: UIControl.State.normal)
        
        control.imageView?.contentMode = UIView.ContentMode.scaleAspectFit
        
        control.rx.tap.withUnretained(self).subscribe(onNext: { own , _ in
            
            if let atOwn = own.parentViewController as? ST_TIANLightNavigationBarAction{
                atOwn.navigation_item_bar_tap_subscribe(position: .left)
            }else{
                own.parentViewController?.goback_previous_controller()
            }
            
        }).disposed(by: rx.disposeBag)
        
        return control
    }()
    
    
    lazy var right_nav_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
        
        control.rx.tap.withUnretained(self).subscribe(onNext: { own , _ in
            
            if let atOwn = own.parentViewController as? ST_TIANLightNavigationBarAction{
                atOwn.navigation_item_bar_tap_subscribe(position: .right)
            }
            
        }).disposed(by: rx.disposeBag)
        
        return control
    }()
    
    lazy var title_nav_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        
        control.setTitleColor(UIColor(hex: 0x333333), for: .normal)
        
        control.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
        
        return control
    }()
}


//MARK: - OutPut


/// 需要单独处理 ST_TIANLightNavigationBar 事件 请实现
protocol ST_TIANLightNavigationBarAction {
    func navigation_item_bar_tap_subscribe(position:ST_TIANLightNavigationBarItemPosition)
}

enum ST_TIANLightNavigationBarItemPosition {
    case left
    case right
    case center
}
